package cn.iocoder.yudao.module.biz.service.expand.powerAccount;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.expand.powerAccount.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.expand.powerAccount.ExpandTargetPowerAccountDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.biz.dal.mysql.expand.powerAccount.ExpandTargetPowerAccountMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 拓展目标_客户_用电户号 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ExpandTargetPowerAccountServiceImpl implements ExpandTargetPowerAccountService {

    @Resource
    private ExpandTargetPowerAccountMapper expandTargetPowerAccountMapper;

    @Override
    public Long createExpandTargetPowerAccount(ExpandTargetPowerAccountSaveReqVO createReqVO) {
        // 插入
        ExpandTargetPowerAccountDO expandTargetPowerAccount = BeanUtils.toBean(createReqVO, ExpandTargetPowerAccountDO.class);
        expandTargetPowerAccountMapper.insert(expandTargetPowerAccount);

        // 返回
        return expandTargetPowerAccount.getId();
    }

    @Override
    public void updateExpandTargetPowerAccount(ExpandTargetPowerAccountSaveReqVO updateReqVO) {
        // 校验存在
        validateExpandTargetPowerAccountExists(updateReqVO.getId());
        // 更新
        ExpandTargetPowerAccountDO updateObj = BeanUtils.toBean(updateReqVO, ExpandTargetPowerAccountDO.class);
        expandTargetPowerAccountMapper.updateById(updateObj);
    }

    @Override
    public void deleteExpandTargetPowerAccount(Long id) {
        // 校验存在
        validateExpandTargetPowerAccountExists(id);
        // 删除
        expandTargetPowerAccountMapper.deleteById(id);
    }

    @Override
        public void deleteExpandTargetPowerAccountListByIds(List<Long> ids) {
        // 删除
        expandTargetPowerAccountMapper.deleteByIds(ids);
        }


    private void validateExpandTargetPowerAccountExists(Long id) {
        if (expandTargetPowerAccountMapper.selectById(id) == null) {
            throw exception(BIZ_EXPAND_TARGET_POWER_ACCOUNT_NOT_EXISTS);
        }
    }

    @Override
    public ExpandTargetPowerAccountDO getExpandTargetPowerAccount(Long id) {
        return expandTargetPowerAccountMapper.selectById(id);
    }

    @Override
    public PageResult<ExpandTargetPowerAccountDO> getExpandTargetPowerAccountPage(ExpandTargetPowerAccountPageReqVO pageReqVO) {
        return expandTargetPowerAccountMapper.selectPage(pageReqVO);
    }

}